import request from "@/utils/request";

//内存条型号导入接口
export const reqMemoryImportExcel = (data) => {
  return request({
    url: "/memoryModules/importExcel",
    method: "post",
    data: data,
  });
};
//排产订单明细导入接口
export const reqOrderImportExcel = (data) => {
  return request({
    url: "/productionOrderDetails/importExcel",
    method: "post",
    data: data,
  });
};

//根据产品编码、物料编码、型号查询列表数据
export const reqMemoryModulesListBySearch = (parentCode, childCode, model) => {
  return request({
    url: "/memoryModules/pages",
    method: "get",
    params: {
      parentCode,
      childCode,
      model,
    },
  });
};

/**
 * 散备件校验相关接口
 */

//根据备货单号 查询产品编号和总数量 stockUpOdd:备货单号
export function reqProductionOrderDetail(stockUpOdd,lineCode) {
  return request({
    url: "/productionOrderDetails/check",
    method: "get",
    params:{
      stockOrderOrTask:stockUpOdd,
      lineCode
    }
  });
}

//上传21码进行校验
export function reqCheck21Code(barCode_21) {
  return request({
    url: "/memoryModules/check/parentCode/" + barCode_21,
    method: "get",
  });
}

//上传09码进行校验
export function reqCheck09Code(barCode_09) {
  return request({
    url: "/memoryModules/check/childCode",
    method: "post",
    data: {
      childCode: barCode_09,
    },
  });
}

//根据备货单号获取校验pass或fail的记录 stockUpOdd备货单 type: 0 | 1
export function reqRecordsByStockUpOdd(stockUpOdd, type) {
  return request({
    url: "/checkRecords/pages",
    method: "get",
    params: {
      stockOrderOrTask: stockUpOdd,
      type,
      page:1,
      size:100
    },
  });
}

//上传备货单校验记录  stockOrderOrTask:备货单号  data:{parentCode:21条码  childCode:09条码  type: 0 | 1}
export function reqRecordsValidate(data) {
  return request({
    url: "/checkRecords",
    method: "post",
    data: data,
  });
}

//扫完型号码后与系统基数据进行比对
export function reqComparisonSysData(parentCode, childCode, model) {
  return request({
    url: "/memoryModules/check",
    method: "get",
    params: {
      parentCode,
      childCode,
      model,
    },
  });
}

//质检员输入密码解锁
export function reqUnlockScreen(password) {
  return request({
    url: "/customizeUsers/auth/login",
    method: "post",
    data: {
      username: "zhijianyuan",
      password: password,
    },
  });
}

//保存ip和port
export function reqSaveIpAndPort( configIp, configPort, id, configName, configKey) {
  return request({
    url: "/configData",
    method: "post",
    data: {
      id: id,
      configName: "default",
      configKey: "default",
      configIp,
      configPort,
    },
  });
}

//获取保存的ip和端口
export function reqIpAddressAndPort() {
  return request({
    url: "/configData/config/key/" + "default",
    method: "get",
  });
}

//测试数据同步临时接口
export function reqSynchronizationDataTest(code) {
  return request({
    url: "/test/write",
    method: "get",
    params: {
      code,
    },
  });
}

//一致性校验接口保存校验记录
export function reqSaveInvalidateRecord( physicalBarcode, outerBoxBarcode,checkResult ) {
  return request({
    url: "/consistencyChecks",
    method: "post",
    data: {
      physicalBarcode,
      outerBoxBarcode,
      checkResult,
    },
  });
}

//获取一致性校验页面的pass和fail记录
export function reqPassAndFailRecordCount() {
  return request({
    url: "/consistencyChecks/count",
    method: "get",
  });
}

//用户设置获取用户信息
export function reqUserInfo() {
  return request({
    url: "/customizeUsers/find/user",
    method: "post",
    data: {
      username: "zhijianyuan",
    },
  });
}

//用户重置密码
export function reqResetPassword(pwd_old, pwd_new, date) {
  return request({
    url: "/customizeUsers/reset",
    method:"post",
    data: {
      username:"zhijianyuan",
      passwordOld: pwd_old,
      passwordNew: pwd_new,
      expiredDate:date
    },
  });
}

//上传记录获取记录的下载地址
export function reqExportExcel(params) {
  return request({
    url: "/checkRecords/exportExcel",
    method: "get",
    params: {
      stockOrderOrTask: params.stockOrder,
      lineCode:params.lineCode,
      startDate:params.startDate,
      endDate:params.endDate
    },
    responseType: "blob",
    timeout:1000 * 60 * 10
  });
}

//数据推送到rpa
/* export function reqPutRPA(stockUpOdd) {
  return request({
    url: "/rpaPassRecords/save/detail",
    method: "post",
    data: {
      stockOrder: stockUpOdd,
    },
  });
} */
//数据推送到后端
export function reqPutRPA (parentCode, childCode, snCode, stockOrder) {
  return request({
    url:"/rpaSends/write",
    method:"post",
    data:{
      parentCode,
      childCode,
      snCode,
      stockOrder
    }
  })
}

//保存数据推送结果记录
export function reqSaveResultRecords (stockOrder, parentCode, childCode, snCode) {
  return request({
    url:"/rpaSendRecords",
    method:"post",
    data:{
      stockOrder,
      parentCode,
      childCode,
      snCode,
      result:true,
      type:0
    }
  })
}

//查询备货单的完成数量
export function reqStockUpOddFinishedNum(stockUpOdd) {
  return request({
    url: "/rpaSendRecords/finishCount",
    method: "post",
    data:{
      stockOrder:stockUpOdd
    }
  });
}

//开启了基准校验后，每采集到一次21码，就发请求校验
export function reqInvalidateInKindBarCode_21(inKindBarCode_21) {
  return request({
    url: "/consistencyChecks/check/" + inKindBarCode_21,
    method: "get",
  });
}

// --- 2024 09 09 修改以下接口

// 保存排产订单数据
export function saveProductDetail(data) {
  return request({
    url: "/productionOrderDetails",
    method: "post",
    data,
  });
}

//排产订单列表数据
export const reqProductOrderList = (params) => {
  return request({
    url: "/productionOrderDetails/pages",
    method: "get",
    params,
  });
};

// 删除排产订单数据
export function deleteProductOrderList(id) {
  return request({
    url: "/productionOrderDetails/" + id,
    method: "delete",
    physics: true, // 物理删除
  });
}

//获取内存条模块数据
export const reqMemoryModulesList = (params) => {
  return request({
    url: "/memoryModules/pages",
    method: "get",
    params,
  });
};

// 新增内存条模块数据
export function saveMemoryModules(data) {
  return request({
    url: "/memoryModules",
    method: "post",
    data,
  });
}

// 删除内存条模块数据
export function deleteMemoryModules(id) {
  return request({
    url: "/memoryModules/" + id,
    method: "delete",
    physics: true, // 物理删除
  });
}





//新增产线 lineCode:产线编码   lineIp:产线ip
export function reqSaveProductionIPBinds (lineCode, lineIp, lineIp2, lineName) {
  return request ({
    url:"/productionIPBinds",
    method:"post",
    data:{
      lineCode,
      lineIp,
      lineIp2,
      lineName
    }
  })
}

//分页查询产线编码及ip
export function reqProductionIPBindsList (page, size) {
  return request({
    url:"/productionIPBinds/pages",
    method:"get",
    params:{
      page,
      size
    }
  })
}

//修改产线编码及ip
export function reqUpdateProductionIPBinds (data) {
  return request({
    url:"/productionIPBinds",
    method:"put",
    data:data
  })
}

//删除产线编码及ip
export function reqDeleteProductionIPBinds (id) {
  return request({
    url:"/productionIPBinds/" + id,
    method:"delete"
  })
}

//一致性校验记录结果上传
export function reqUploadConsistenceRecords (stockOrder, inKind, outBox, unPassCodes, checkResult){
  return request({
    url:"/consistenceRecords",
    method:"post",
    data:{
      stockOrder,
      inKind,
      outBox,
      unPassCodes,
      checkResult
    }
  })
}

//一致性校验记录导出结果 stockOrder无则导出全部的记录
export function reqExportConsistenceRecords (params) {
  return request({
    url:"/consistenceRecords/exportExcel",
    method:"get",
    params: {
      stockOrder:params.stockOrder,
      lineCode:params.lineCode,
      startDate:params.startDate,
      endDate:params.endDate
    },
    responseType:"blob",
    timeout:1000 * 60 * 10
  })
}

//获取所有产线列表接口
export function reqProductionIPBinds () {
  return request({
    url:"/productionIPBinds",
    method:"get"
  })
}


//手动采码最终推送数据至rpa
export function reqSendRpa (stockOrder,parentCode, childCode, snCode, lineCode) {
  return request({
    url:"/rpaSends/write",
    method:"post",
    data:{
      stockOrder,
      parentCode,
      childCode,
      snCode,
      lineCode
    }
  })
}

//自动线输入备货单和09码后上传到后端接口
export function reqSendData (lineCode, stockOrder, childCode, isOpenModelCheck) {
  return request({
    url:"/stagings",
    method:"post",
    data:{
      lineCode,
      stockOrder,
      childCode,
      isOpenModelCheck
    }
  })
}

//将备货单上传
export function reqSendStockOrder (stockOrder, lineCode) {
  return request({
    url:"/rpaSends/stockOrder/write",
    method:"post",
    data:{
      stockOrder,
      lineCode
    }
  })
}

//20240924
//排产表编辑
export function reqUpdateProductionOrderDetails (data) {
  return request({
    url:"/productionOrderDetails",
    method:"put",
    data
  })
}

//基表编辑
export function reqUpdateMemoryModulesDetails (data){
  return request({
    url:"/memoryModules",
    method:"put",
    data
  })
}

//导出排产表模板
export function reqExportTemplateOfProductionOrder (){
  return request({
    url:"/productionOrderDetails/template/export",
    method:"get",
    responseType:'blob'
  })
}

//导出基表模板
export function reqExportTemplateOfMemoryModules () {
  return request({
    url:"/memoryModules/template/export",
    method:"get",
    responseType:'blob'
  })
}